package com.qian.ddj.web.controller;

import com.qian.api.ddj.model.Business;
import com.qian.api.ddj.model.StatusDict;
import com.qian.api.ddj.service.IBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ddj/loginCode")
public class LoginCodeController {

    @Autowired
    private IBusinessService businessService;

    @PostMapping("/success/{id}")
    public void success(@PathVariable Integer id) {
        Business business = new Business();
        business.setId(id);
        business.setBackup4(StatusDict.SUCCESS.toString());
        businessService.save(business);
    }

    @PostMapping("/refresh/{id}")
    public void fail(@PathVariable Integer id) {
        Business business = new Business();
        business.setId(id);
        business.setBackup3("");
        business.setBackup4(StatusDict.FAIL.toString());
        businessService.save(business);
    }

    @GetMapping("/{id}")
    public String code(@PathVariable Integer id) {
        Business business = businessService.findById(id);
        return business.getBackup3();
    }
}
